package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.LoginInfo;
import com.ruoyi.system.service.ILoginInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户登陆记录表Controller
 * 
 * @author ruoyi
 * @date 2024-06-18
 */
@Controller
@RequestMapping("/system/logininfo")
public class LoginInfoController extends BaseController
{
    private String prefix = "system/logininfo";

    @Autowired
    private ILoginInfoService loginInfoService;

    @RequiresPermissions("system:logininfo:view")
    @GetMapping()
    public String logininfo()
    {
        return prefix + "/logininfo";
    }

    /**
     * 查询用户登陆记录表列表
     */
    @RequiresPermissions("system:logininfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LoginInfo loginInfo)
    {
        startPage();
        List<LoginInfo> list = loginInfoService.selectLoginInfoList(loginInfo);
        return getDataTable(list);
    }

    /**
     * 导出用户登陆记录表列表
     */
    @RequiresPermissions("system:logininfo:export")
    @Log(title = "用户登陆记录表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LoginInfo loginInfo)
    {
        List<LoginInfo> list = loginInfoService.selectLoginInfoList(loginInfo);
        ExcelUtil<LoginInfo> util = new ExcelUtil<LoginInfo>(LoginInfo.class);
        return util.exportExcel(list, "用户登陆记录表数据");
    }

    /**
     * 新增用户登陆记录表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户登陆记录表
     */
    @RequiresPermissions("system:logininfo:add")
    @Log(title = "用户登陆记录表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LoginInfo loginInfo)
    {
        return toAjax(loginInfoService.insertLoginInfo(loginInfo));
    }

    /**
     * 修改用户登陆记录表
     */
    @RequiresPermissions("system:logininfo:edit")
    @GetMapping("/edit/{liId}")
    public String edit(@PathVariable("liId") Long liId, ModelMap mmap)
    {
        LoginInfo loginInfo = loginInfoService.selectLoginInfoByLiId(liId);
        mmap.put("loginInfo", loginInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户登陆记录表
     */
    @RequiresPermissions("system:logininfo:edit")
    @Log(title = "用户登陆记录表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LoginInfo loginInfo)
    {
        return toAjax(loginInfoService.updateLoginInfo(loginInfo));
    }

    /**
     * 删除用户登陆记录表
     */
    @RequiresPermissions("system:logininfo:remove")
    @Log(title = "用户登陆记录表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(loginInfoService.deleteLoginInfoByLiIds(ids));
    }
}
